package or.exa.cangguan.service.impl;

import io.swagger.models.auth.In;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.entity.po.UserInfo;
import or.exa.cangguan.mapper.UserInfoMapper;
import or.exa.cangguan.service.RegisterService;
import or.exa.cangguan.utils.DigestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Slf4j
@Service
public class RegisterServiceimpl implements RegisterService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private DigestUtil digestUtil;


    @Override
    public Integer register(String userName, String userPassword) {
        Date date = new Date(System.currentTimeMillis());

        String password = digestUtil.hmacSign(userPassword);


        UserInfo userInfo = new UserInfo();
        userInfo.setUserName(userName);
        userInfo.setUserPassword(password);
        userInfo.setCreateTime(date);
        userInfo.setUpdateTime(date);
        log.info("userInfo:{}", userInfo);

        int i = userInfoMapper.insertSelective(userInfo);
        return i;

    }
}
